package com.wshare.controller;


import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wshare.dao.interfaces.IAccountDao;
import com.wshare.entity.Account;

@Controller
public class IndexController {

	@Autowired
	IAccountDao accountDao;
	
	Logger logger = Logger.getLogger(Account.class);
	
	@PreAuthorize("hasRole('ROLE_ADMIN')")
	@RequestMapping(value = {"/index/index","/index/index/","/index","/index/"})
	public String index(Model model)
	{
		System.out.println("mvc successfule");
		model.addAttribute("msg","hi every one");
		return "indexIndex";
	}
	
	@RequestMapping("/login")
	public String login(Model model)
	{
		return "indexLogin";
	}
	
	@PreAuthorize("hasPermission(#post,'DELETE')")
	@RequestMapping("/test")
	public String test(Model model)
	{
		Account acc = accountDao.getByCol("username","Admin").get(0);
		model.addAttribute("acc",acc);
		return "test";
	}
	@RequestMapping("/logger")
	@ResponseBody
	public String logger(){
		int a = 3,b = 0,c;
		try {
			c = a/b;
		} catch (Exception e) {
			logger.error("Loi roi ba con oi", e);
		}
		return "ok man";
	}
	
}
